Add gdk_profiler_add_markf() to do printf formating
authorAlexander Larsson <alexl@redhat.com>
Wed, 12 Feb 2020 08:56:10 +0000 (09:56 +0100)
committerAlexander Larsson <alexl@redhat.com>
Wed, 12 Feb 2020 08:58:52 +0000 (09:58 +0100)
This allows us to avoid hand-rolling g_strdup_printf calls,
but also moves the printf into the called function where
it doesn't bloat the code of the calling function if the profiler
is not running.

gdk/gdkprofiler.c
gdk/gdkprofilerprivate.h

index 5b4e976110576706ae00fb2656783dfa180e2bce..3554c0104b4b8e7ee4e3c15b0265d27ad8287049 100644 (file)
@@ -100,6 +100,31 @@ gdk_profiler_add_mark (gint64      start,
                                    "gtk", name, message);
 }
 
+void
+gdk_profiler_add_markf (gint64      start,
+                        guint64     duration,
+                        const char *name,
+                        const char *format,
+                        ...)
+{
+  va_list args;
+  char *message;
+
+  if (!running)
+    return;
+
+  va_start (args, format);
+  message = g_strdup_vprintf (format, args);
+  va_end (args);
+
+  sysprof_capture_writer_add_mark (writer,
+                                   start,
+                                   -1, getpid (),
+                                   duration,
+                                   "gtk", name, message);
+  g_free (message);
+}
+
 static guint
 define_counter (const char *name,
                 const char *description,
index 9696c7e2dc3c81e07869541591016b95507fc565..99558e3adfcec2acc4bfb8326f9808dab5312218 100644 (file)
@@ -30,6 +30,11 @@ void     gdk_profiler_add_mark   (gint64           start,
                                   guint64          duration,
                                   const char      *name,
                                   const char      *message);
+void     gdk_profiler_add_markf   (gint64           start,
+                                   guint64          duration,
+                                   const char      *name,
+                                   const char      *format,
+                                   ...)  G_GNUC_PRINTF (4, 5);
 guint    gdk_profiler_define_counter (const char *name,
                                       const char *description);
 void     gdk_profiler_set_counter    (guint  id,